const BaseHandler = require('../base-handler');
const SystemServices = require('../../../constants').SystemServices;
const HTTP_VERBS = require('../../../constants').HTTP_VERBS;
/**
 * 选择不同的门店更改session中的storeId
 * @class ModifyStoreHandler
 * @extends {BaseHandler}
 */
class StoreRolesHandler extends BaseHandler {
    get pattern() {
        return "/change/:type";
    }

    doGET(request, response) {
        if (request.params.type == 'store') {
            request.session.user.storeId = request.query.storeId;
            request.session.user.storeName = request.query.storeName;
            response.json({
                success: true
            });
        } else {
            this.Controller.commonSearch({ type: 'role', userId: request.session.user.id }, (result) => {
                if (result.error) {
                    return response.end();
                }
                request.session.user.roleIds = result.roleIds;
            })
        }
    }

    setup() {
        this.registerVerb(HTTP_VERBS.GET, this.doGET);
    }
}

module.exports = StoreRolesHandler;